<div id="content">
    <?php

if($vendre) {
	if($vendre == 1) {
		echo '<p>Veuillez remplir tous les champs svp </p>';
	}

	else {
		echo '<p>Votre compte a bien été crée !</p>';
		echo '<p>Veuillez vous identifier : <a href="index.php?a=connexion"> Connexion </a>';
	}
}
else {
	?>
	<form class="well" action="" method="POST" enctype="multipart/form-data">
        <input type="hidden" name="longitude" id="longitude" />
        <input type="hidden" name="latitude" id="latitude" />
		<h2>Vendre</h2>
        <label for="categorie">Catégorie</label>
        <select id="categorie" name="categorie">
            <option value="vehicule">Véhicules</option>
            <option value="immobiblier">Immobilier</option>
            <option value="multimedia">Multimédia</option>
            <option value="maison">Maison</option>
            <option value="loisirs">Loisirs</option>
            <option value="autres">Autres</option>
        </select>
        <br /><br />
		<label for="name">Nom du produit :</label>
		<input type="text" name="name" id="name" />
		<br />
		<label for="description">Description :</label>
		<input type="text" name="description" id="description" />
		<br/>
		<label for="prix">Prix (en €) :</label>
		<input type="number" name="prix" id="prix" step="0.01"/>
		<label for="image">Image :</label>
		<input name="uploadedfile" type="file" accept="image/*"/><br />
		<br />
		<label for="lieu">Ville :</label>
        <input type="text" name="ville" id="ville"/>
        <label for="lieu">Couleur :</label>
		<input type="text" name="couleur" id="couleur"/>
        <input type="submit" value="Vendre"/>
	</form>
<script>
      function displayLocation(latitude,longitude){
        var request = new XMLHttpRequest();

        var method = 'GET';
        var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+latitude+','+longitude+'&sensor=true';
        var async = true;

        request.open(method, url, async);
        request.onreadystatechange = function(){
          if(request.readyState == 4 && request.status == 200){
            var data = JSON.parse(request.responseText);
            var address = data.results[0];
            $("#ville").val(address.formatted_address);
          }
        };
        request.send();
      };

      var successCallback = function(position){
        var x = position.coords.latitude;
        var y = position.coords.longitude;
        displayLocation(x,y);
      };

      var errorCallback = function(error){
        var errorMessage = 'Unknown error';
        switch(error.code) {
          case 1:
            errorMessage = 'Permission denied';
            break;
          case 2:
            errorMessage = 'Position unavailable';
            break;
          case 3:
            errorMessage = 'Timeout';
            break;
        }
        document.write(errorMessage);
      };

      var options = {
        enableHighAccuracy: true,
        timeout: 1000,
        maximumAge: 0
      };

      navigator.geolocation.getCurrentPosition(successCallback,errorCallback,options);
    </script>
	
	
	<?php
}
?>
</div>
